//
//  MyObject.m
//  RunTime的一些深入
//
//  Created by ZhouFahong on 16/7/27.
//  Copyright © 2016年 ZhouFahong. All rights reserved.
//

#import "MyObject.h"
#import "objc/runtime.h"

static NSMutableDictionary *map = nil;

@implementation MyObject

+ (void)load

{
    
    map = [NSMutableDictionary dictionary];
    
    
    
    map[@"name1"]                = @"name";
    
    map[@"status1"]              = @"status";
    
    map[@"name2"]                = @"name";
    
    map[@"status2"]              = @"status";
    
}

// @{@"name1": "张三", @"status1": @"start"}



// @{@"name2": "张三", @"status2": @"end"}

- (void)setDataWithDic:(NSDictionary *)dic

{
    
    [dic enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
        
        
        
        NSString *propertyKey = [self propertyForKey:key];
        
        
        
        if (propertyKey)
        
        {
            
            objc_property_t property = class_getProperty([self class], [propertyKey UTF8String]);
            
            
            
            // TODO: 针对特殊数据类型做处理
            
            NSString *attributeString = [NSString stringWithCString:property_getAttributes(property) encoding:NSUTF8StringEncoding];
            
            
            
//            ...
            
            
            
            [self setValue:obj forKey:propertyKey];
            
        }
        
    }];
    
}

- (NSString *)propertyForKey:(NSString *)originalKey
{
    NSDictionary *dict = [NSDictionary dictionary];
    return [dict objectForKey:originalKey];
}

@end
